home *** CD-ROM | disk | FTP | other *** search
- Path: nwlink.com!usenet
- From: Teresa Reiko <tjr19@mail.nwlink.com>
- Newsgroups: comp.lang.c
- Subject: Re: Obtaining file lists in C?
- Date: 15 Apr 1996 14:14:57 GMT
- Organization: Northwest Link
- Message-ID: <4ktll1$bk5@texas.nwlink.com>
- References: <gcraig.1.001653A2@interaccess.com>
- NNTP-Posting-Host: port55.annex2.nwlink.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.2 (Windows; U; 16bit)
-
- gcraig@interaccess.com (George Craig) wrote:
- >Could someone please tell me just one of the many ways I could implement an
- >efficient file listing technique in standard ANSI or k&R c?
- >
- >I.e, I want to obtain a listing of the files in the current directory - could
- >I use a pointer to an array of strings? Whereas the strings are actually the
- >names of the files in the current directory.
- >
- >If I could do that... (which I am almost positive I can) how would I obtain
- >the file listing into the variables. I want to avoid using system() and I
- >surely don't want to go low-level and read the file system's table(s) - any
- >and all help will surely be appreciated -- Thank you
-
- This is impossible in standard C. There is no standard C function to
- read the directories. Most C implementations include one, however, so
- for instance in Borland C you can use findfirst and findnext, or you
- can use opendir, readdir, etc.
-
- system() is a standard C function, but its use for this would not be
- portable either because: on Unix the directory list command is 'ls',
- but on DOS it is 'dir', so you can't count on that.
-
- Unfortunately, this sort of program is just not portable!
-
- ----- for every vision there is an equal and opposite revision ... -----
- ------------------------------------------------------------------------
- Teresa Reiko Chief Programmer, Tenbyte Software tjr19@nwlink.com
- ------------------------------------------------------------------------
-
-